package vn.vfriends.mcms.admin.model;

import java.io.Serializable;
import org.apache.commons.net.ftp.FTPFile;

/**
 *
 * @author tuan@vfriends.vn
 */
public class SiteDoc implements Serializable {

    private String name;
    
    private String path;
    
    private boolean isFile;
    
    public enum Type {
        DOCUMENT("DOCUMENT"), IMAGE("IMAGE"), VIDEO("VIDEO");
        
        private String type;
        
        private Type(String type) {
            this.type = type;
        }

        public String getTpe() {
            return type;
        }
        
        @Override
        public String toString() {
            return type;
        }
    }
    
    private Type type;
    
    public SiteDoc(String name, String path, boolean isFile) {
        this.name = name;
        this.path = path;
        this.isFile = isFile;
        initFileType();
    }

    public boolean isFile() {
        return isFile;
    }
    
    private void initFileType() {
        String[] tmp = name.split("\\.");
        if(tmp != null) {
            String fileExtention = tmp[tmp.length-1];
            
            if (fileExtention == null || fileExtention.length() == 0) {
                type = Type.DOCUMENT;
            } else if (fileExtention.toUpperCase().equals("PNG")
                    || fileExtention.toUpperCase().equals("JPEG")
                    || fileExtention.toUpperCase().equals("GIF")
                    || fileExtention.toUpperCase().equals("BMP")) {
                type = Type.IMAGE;
            } else if (fileExtention.toUpperCase().equals("MP3")
                    || fileExtention.toUpperCase().equals("MP4")
                    || fileExtention.toUpperCase().equals("WAV")
                    || fileExtention.toUpperCase().equals("WMA")
                    || fileExtention.toUpperCase().equals("WMV")) {
                type = Type.VIDEO;
            } else {
                type = Type.DOCUMENT;
            }
        } else {
            type = Type.DOCUMENT;
        }
    }
    
    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }
}
